package com.bluezone.dec.system.controller;

import com.alibaba.fastjson.JSONArray;
import com.bluezone.dec.common.JsonResult;
import com.bluezone.dec.system.service.HiddenTroubleInvestigationStatisticsService;
import com.bluezone.dec.utils.JSONUtils;
import com.google.common.base.Strings;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author HHL
 * @description 隐患排查统计
 * @date 2018/9/27 - 13:16
 */
@Api(tags = "隐患排查统计")
@RequestMapping("/dec/hidden-trouble-Statistics")
@RestController
public class HiddenTroubleInvestigationStatisticsController {

    @Autowired
    private HiddenTroubleInvestigationStatisticsService hidTroubleInvestService;

    @ApiOperation("获取标题卡片的数据")
    @GetMapping("/hidden-card-data")
    public JsonResult getHiddenCardData() {

        /* 获取隐患排查标题1_隐患排查统计 */
        String hiddenTroubleNum = hidTroubleInvestService.getHiddenTroubleInvestStatistics();

        /* 获取隐患排查标题2_企业执法情况统计 */
        String entLawNum = hidTroubleInvestService.getEnterpriseLawEnforcementCount();

        /* 获取隐患排查标题3_隐患整改情况统计 */
        String hiddenRectNum = hidTroubleInvestService.getHiddenDangerReformCount();

        Map<String, Object> titleMap = new HashMap<>();

        titleMap.put("hiddenRectNum", Strings.isNullOrEmpty(hiddenRectNum) ? 0 : Integer.parseInt(hiddenRectNum));
        titleMap.put("entLawNum", Strings.isNullOrEmpty(entLawNum) ? 0 : Integer.parseInt(entLawNum));
        titleMap.put("hiddenTroubleNum", Strings.isNullOrEmpty(hiddenTroubleNum) ? 0 : Integer.parseInt(hiddenTroubleNum));

        return new JsonResult().ok(titleMap);
    }


    @ApiOperation("获取隐患整改数据")
    @GetMapping("/hidden-rect-data")
    public JsonResult getHiddenRectData() {

        List<Map<String, Object>> resultList = hidTroubleInvestService.getHiddenDangerReformInfo();

        return new JsonResult().ok(resultList);

    }


    @ApiOperation("获取处罚情况数据")
    @GetMapping("/hidden-punish-data")
    public JsonResult getHiddenPunishData() {

        String hiddenPunish = JSONUtils.getJsonFile("hiddenPunish.json");

        JSONArray hiddenPunishArray = JSONArray.parseArray(hiddenPunish);

        return new JsonResult().ok(hiddenPunishArray);

    }


    @ApiOperation("获取隐患排查所有类别统计数据")
    @GetMapping("/hidden-category-all-data")
    public JsonResult getHiddenCategoryAllData() {
        Map<String, Object> hiddenCategoryAllObj = hidTroubleInvestService.getHiddenCategoryAllData();
        return new JsonResult().ok(hiddenCategoryAllObj);
    }


    @ApiOperation("获取隐患排查基础类别统计数据")
    @GetMapping("/hidden-category-basis-data")
    public JsonResult getHiddenCategoryBasisData() {
        List<Map<String, Object>> basicManagement = hidTroubleInvestService.getBasicManagement();
        return new JsonResult().ok(basicManagement);
    }


    @ApiOperation("获取隐患排查现场类别统计数据")
    @GetMapping("/hidden-category-site-data")
    public JsonResult getHiddenCategorySiteData() {
        List<Map<String, Object>> siteManagementList = hidTroubleInvestService.getSiteManagement();
        return new JsonResult().ok(siteManagementList);

    }

    @ApiOperation("获取企业自查数据")
    @GetMapping("/hidden-law-self-data")
    public JsonResult getHiddenLawSelfData() {
        List<Map<String, Object>> hiddenLawSelfArray = hidTroubleInvestService.getEnterpriseSelfCheck();
        return new JsonResult().ok(hiddenLawSelfArray);

    }

    @ApiOperation("获取执法检查数据")
    @GetMapping("/hidden-law-data")
    public JsonResult getHiddenLawData() {
        List<Map<String, Object>> resultList = hidTroubleInvestService.getLawEnforcementInspection();
        return new JsonResult().ok(resultList);
    }
}
